package com.acme.bankapp.service.bank.listener.email;

/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class EmailProducer implements Runnable {
    private final Email email;
    private final BankBlockingQueue<Email> queue;

    public EmailProducer(final Email email, final BankBlockingQueue<Email> blockingQueue) {
        this.email = email;
        this.queue = blockingQueue;
    }

    @Override
    public void run() {
        try {
            queue.add(email);
        }
        catch (InterruptedException interruptedException) {
            interruptedException.printStackTrace();
            System.err.println(interruptedException.getMessage());
            Thread.currentThread().interrupt();
        }
        catch (IllegalStateException illegalStateException) {
            illegalStateException.printStackTrace();
            System.err.println(illegalStateException.getMessage());
        }
    }
}
